package com.wuyb.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * 连接Flask的Config
 *
 * @Author: wyb
 * @Date: 2024/01/03/14:57
 * @Description:
 */
@Configuration
public class RestTemplateConfig {

    /**
     * 建立HTTP连接请求工厂
     * @return
     */
    @Bean
    public ClientHttpRequestFactory simpleClientHttpRequestFactory(){
        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
        // 建立连接所用的时间
        factory.setConnectTimeout(10000);
        // 建立连接后从服务器读取到可用资源所用的时间
        factory.setReadTimeout(6000);
        return factory;

    }

    @Bean
    public RestTemplate restTemplate(ClientHttpRequestFactory factory){
        return new RestTemplate(factory);
    }
}
